package com.wuyou.simple;

import javax.swing.tree.TreeNode;

/**
 * 2331. 计算布尔二叉树的值
 */
public class EvaluateTree {


    // 递归
    //
    public static boolean solution_1(TreeNode1 root) {
        if (root.left == null && root.right == null) {
            return root.val != 0;
        }
        return root.val == 2 ? solution_1(root.left) || solution_1(root.right) : solution_1(root.left) && solution_1(root.right);
    }
}

class TreeNode1 {
    int val;
    TreeNode1 left;
    TreeNode1 right;

    TreeNode1() {
    }

    TreeNode1(int val) {
        this.val = val;
    }

    TreeNode1(int val, TreeNode1 left, TreeNode1 right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
